package com.example.mall.web.controller;

import com.example.mall.domain.UserTrafficStatistics;
import com.example.mall.dto.UserTrafficStatisticsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.UserTrafficStatisticsQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IUserTrafficStatisticsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/userTrafficStatistics")
public class UserTrafficStatisticsController {

    @Autowired
    public IUserTrafficStatisticsService userTrafficStatisticsService;

    /**
     * 分页查询用户访问量统计表信息
     * @param userTrafficStatisticsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询用户访问量统计表信息",notes = "分页查询用户访问量统计表信息",httpMethod = "GET")
    public JSONResult queryPage(UserTrafficStatisticsQuery userTrafficStatisticsQuery){
        PageDTO<UserTrafficStatisticsDto> userTrafficStatisticsDtoPageDTO = userTrafficStatisticsService.queryPage(userTrafficStatisticsQuery);
        return JSONResult.success("查询成功",userTrafficStatisticsDtoPageDTO);
    }

    /**
     * 根据id查询用户访问量统计表信息
     * @param id
     * @return
     */
    @GetMapping("query/{id}")
    @ApiOperation(value = "根据id查询用户访问量统计表信息",notes = "根据id查询用户访问量统计表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.STATID_NOT_ID);
        }
        UserTrafficStatistics userTrafficStatistics = userTrafficStatisticsService.getById(id);
        return JSONResult.success("查询成功",userTrafficStatistics);
    }

    /**
     * 根据id查询用户访问量统计表信息
     * @param id
     * @return
     */
    @GetMapping("queryUserTrafficStatisticsById/{id}")
    @ApiOperation(value = "根据id查询用户访问量统计表信息",notes = "根据id查询用户访问量统计表信息",httpMethod = "GET")
    public JSONResult queryUserTrafficStatisticsById(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.STATID_NOT_ID);
        }
        UserTrafficStatistics userTrafficStatistics = userTrafficStatisticsService.queryUserTrafficStatisticsById(id);
        return JSONResult.success("查询成功",userTrafficStatistics);
    }

    /**
     * 查询全部用户访问量统计表信息
     * @param
     * @return
     */
    @GetMapping("queryUserTrafficStatisticsList")
    @ApiOperation(value = "查询全部用户访问量统计表信息",notes = "查询全部用户访问量统计表信息",httpMethod = "GET")
    public JSONResult queryUserTrafficStatisticsList(){
        List<UserTrafficStatistics> userTrafficStatistics = userTrafficStatisticsService.queryUserTrafficStatisticsList();
        return JSONResult.success("查询成功",userTrafficStatistics);
    }

    /**
     * 新增用户访问量统计表
     * @param userTrafficStatisticsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增用户访问量统计表",notes = "新增用户访问量统计表",httpMethod = "POST")
    public JSONResult insert(@RequestBody UserTrafficStatisticsDto userTrafficStatisticsDto){
        userTrafficStatisticsService.insert(userTrafficStatisticsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改用户访问量统计表信息
     * @param userTrafficStatisticsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改用户访问量统计表信息",notes = "修改用户访问量统计表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody UserTrafficStatisticsDto userTrafficStatisticsDto){
        userTrafficStatisticsService.update(userTrafficStatisticsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除用户访问量统计表信息
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除用户访问量统计表信息",notes = "删除用户访问量统计表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activitiesProductId") Long id) {
        userTrafficStatisticsService.delete(id);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除用户访问量统计表信息
     * @param ids
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除用户访问量统计表信息",notes = "批量删除用户访问量统计表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> ids) {
        userTrafficStatisticsService.deleteBatch(ids);
        return JSONResult.success("批量删除成功");
    }
}
